package com.ruoyi.cderp.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.CustomerSettleSheet;
import com.ruoyi.cderp.service.ICustomerSettleSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户结算单Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/CustomerSettleSheet")
public class CustomerSettleSheetController extends BaseController
{
    @Autowired
    private ICustomerSettleSheetService customerSettleSheetService;

    /**
     * 查询客户结算单列表
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerSettleSheet customerSettleSheet)
    {
        startPage();
        List<CustomerSettleSheet> list = customerSettleSheetService.selectCustomerSettleSheetList(customerSettleSheet);
        return getDataTable(list);
    }

    /**
     * 新增时查询关于客户的对账类型单据
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:query')")
    @GetMapping("/query")
    public AjaxResult getInfoList(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam String customerId
    )
    {
        return success(customerSettleSheetService.selectFeeSheetDetailList(startDate,endDate,customerId));
    }




    /**
     * 导出客户结算单列表
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:export')")
    @Log(title = "客户结算单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerSettleSheet customerSettleSheet)
    {
        List<CustomerSettleSheet> list = customerSettleSheetService.selectCustomerSettleSheetList(customerSettleSheet);
        ExcelUtil<CustomerSettleSheet> util = new ExcelUtil<CustomerSettleSheet>(CustomerSettleSheet.class);
        util.exportExcel(response, list, "客户结算单数据");
    }

    /**
     * 获取客户结算单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(customerSettleSheetService.selectCustomerSettleSheetById(id));
    }

    /**
     * 新增客户结算单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:add')")
    @Log(title = "客户结算单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerSettleSheet customerSettleSheet)
    {
        return toAjax(customerSettleSheetService.insertCustomerSettleSheet(customerSettleSheet));
    }

    /**
     * 修改客户结算单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:edit')")
    @Log(title = "客户结算单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerSettleSheet customerSettleSheet)
    {
        return toAjax(customerSettleSheetService.updateCustomerSettleSheet(customerSettleSheet));
    }

    /**
     * 删除客户结算单
     */
    @PreAuthorize("@ss.hasPermi('system:CustomerSettleSheet:remove')")
    @Log(title = "客户结算单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customerSettleSheetService.deleteCustomerSettleSheetByIds(ids));
    }
}
